<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP '库存' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>/javascript/MQuery.js"></script>

		<script type="text/javascript">
		var url = "<%=basePath%>/servlet/InventoryServlet"
		function addInventory(){
			MQuery.url = "<%=basePath%>/servlet/InventoryServlet";
			MQuery.data.forward = "addInventory";
			MQuery.data.cinvCode = "12345678";//存货编码
			MQuery.data.cinvName = "什么东西12345678";//存货名称
			MQuery.data.cinvCcode = "01002";//存货分类
			MQuery.data.cshopUnit = "001";//单位编码, 通过单位列表选择获取, 比如 个, 盒 , 件
			MQuery.data.ccomUnitCode = "001";//同上
			MQuery.responseFun = addSuccess;
			MQuery.submit();
			
			function addSuccess(json){//json:返回的json对象 text:返回的json格式的字符串
				alert("添加成功");
			}
		}
		
		
		function getInventoryNumber(){
			if(!$("#cinvCode").val()){
				alert("请输入存货编号");
				return;
			}
			MQuery.url = "<%=basePath%>/servlet/InventoryServlet";
			MQuery.data.forward = "getInventoryNumber";
			MQuery.data.cinvCode = $("#cinvCode").val();//传入存货的编号
			MQuery.responseFun = getInventoryNumberResponseFunction;
			MQuery.submit();
			
			function getInventoryNumberResponseFunction(json){//返回存货数量 包含 单元
				if(json.status == "success"){
					$("#resultText").text("当前存货数量:"+json.message);
				}else{
					alert(json.message);
				}
			}
		}
		
		function getComputationUnitList(){
		
			MQuery.url = "<%=basePath%>/servlet/InventoryServlet";
			MQuery.data.forward = "getComputationUnit";
			MQuery.responseFun = danweiResponseFun;
			MQuery.submit();
			
			function danweiResponseFun(json){//json 表示单元的一个数组
				$("#myDiv").empty();
				$.each(json,function(index,item){
					$("#myDiv").html($("#myDiv").html()+item.ccomunitCode+" - "+item.ccomUnitName+"</br>");
				});
			}
		}
		
	</script>

	</head>

	<body>
		<li>
			<input type="button" value="addInventory"
				onclick="addInventory()">
		<li> <input id="cinvCode" type="text" /> <input type="button" value="getInventoryNumber" onclick="getInventoryNumber()" >
		<label id="resultText" ></label>
		
		<li> <input type="button" onclick="getComputationUnitList()" value="获取单元列表"><div id="myDiv"></div>
	</body>
</html>
